﻿
using Models.Common;
using Models.Constant;
using Newtonsoft.Json;
using RabbitMQ.Client;
using System.Text;
using UtilsBase;
using UtilsCache;
using UtilsMQ;

namespace ServiceWeb.APIRequest
{
    public class ServiceWebRabbitMQSendMsg
    {
        
        /// 发送设备指令
        /// </summary>
        /// <param name="queuename"></param>
        /// <param name="commandLogModel"></param>
        /// <returns></returns>
        public bool sendMsg(MQReqModel<object> mQReqModel)
        {
            mQReqModel.gatewayTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"));
            string msg = StringJsonSet(mQReqModel);

            Console.WriteLine("############################################################");
            Console.WriteLine("下发网关code:" + UtilsMachineInfo.getGateWayMachineCode());
            Console.WriteLine("时间：" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").ToString());
            Console.WriteLine("下发mq消息推送到网关:" + msg);
            Console.WriteLine("############################################################");

            new ServiceWebMqttClient().sendMsg(msg);
           
            return true;
        }

        public static string StringJsonSet<T>(T data)
        {
            return JsonConvert.SerializeObject(data);
        }



    }

}
